<template>
  <div class="home_wrap">
    <van-pull-refresh v-model="isLoading"
                      @refresh="onRefresh">
      <head-com></head-com>
      <banner-com :bannerlist="bannerlist"></banner-com>
      <index-nav :configure="configure"></index-nav>
      <second-kill :hotgoods="hotgoods"></second-kill>
      <recommed></recommed>
    </van-pull-refresh>
  </div>
</template>
<script>
import headCom from '../../components/head'
import bannerCom from './banner'
import indexNav from './indexNav'
import secondKill from './secondKill'
import recommed from './recommed'
import { getIndexApi } from '../../api/home'
import { mapActions, mapMutations } from 'vuex';
export default {
  components: { headCom, bannerCom, indexNav, secondKill, recommed },
  data () {
    return {
      bannerlist: [],
      configure: [],
      hotgoods: [],
      isLoading: false,//是否在下拉中
    }
  },
  methods: {
    ...mapMutations("homeStore", ["clearList"]),
    ...mapActions("homeStore", ["getRecommedAction"]),
    onRefresh () {
      // 从新加载列表
      this.clearList()//清空数据
      this.getRecommedAction(1).then(() => {
        this.isLoading = false;  //数据获取完毕 停止下拉
      })

    }
  },
  created () {
    // 调取轮播图数据和导航数据
    getIndexApi().then(res => {
      console.log(res)
      console.log(res.data.banner)
      this.bannerlist = res.data.banner;
      this.configure = res.data.configure.concat(res.data.configure)
      this.hotgoods = res.data.hotgoods
    })
  }
}
</script>
<style lang="less">
.home_wrap {
  padding-bottom: 120px;
}
</style>